class TreeNode:
    def __init__(self, x):
        self.val = x
        self.left = None
        self.right = None


class Solution:
    def bianli(self, root1,root2):
        if root1 and root2:
            if root1.val!=root2.val:
                return False
            return self.bianli(root2.right,root1.left) and self.bianli(root1.right,root2.left)
        elif not root1 and not root2:
            return True
        else:
            return False


    def isSymmetric(self, root: TreeNode) -> bool:
        if not root: return True
        ans=self.bianli(root.right,root.left)
        return ans